import {createStore} from 'vuex'
import userModule from './module/user'

const state = {
    token: undefined,// 全局token
    orderId: undefined,// 工单ID
    devicePortList: [],// 设备串口
}

const store = createStore({
    state: state,
    mutations: {
        setDevicePortList(state, ports) {
            state.devicePortList = ports || []
        }
    },
    actions: {
        getDevicePortList({commit}) {
            window.api.serialport.getPortList()
        }
    },
    modules: {
        user: userModule,
    }
})

window.api.serialport.onListPort((_, ports) => {
    store.commit('setDevicePortList', ports)
})

export default store